package com.naizhuai.network.upload;

import android.support.annotation.CheckResult;

import java.util.List;
import java.util.Map;

import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Url;
import rx.Observable;

/**
 * @author：lichenxi
 * @date 2018/1/3 17
 * email：525603977@qq.com
 * Fighting
 */
public interface FileUploadService {

    @Multipart
    @POST
    @CheckResult
    Call<ResponseBody>  uploadFile(@Url String url, @Part MultipartBody.Part file);


    @Multipart
    @POST
    @CheckResult
    Observable<ResponseBody> uploadFileRx(@Url String url, @Part MultipartBody.Part file);

    @Multipart
    @POST
    @CheckResult
    Call<ResponseBody>  uploadFiles(@Url String url, @Part List<MultipartBody.Part> files);


    @Multipart
    @POST
    @CheckResult
    Observable<ResponseBody> uploadFilesRx(@Url String url, @Part List<MultipartBody.Part> files);

    /**
     *  同时上传文件和文本数据
     * @param url
     * @param parammap
     * @param file
     * @return
     * eg:
     * RequestBody description = createPartFromString("hello, this is description speaking");
       RequestBody place = createPartFromString("Magdeburg");
       RequestBody time = createPartFromString("2016");

       HashMap<String, RequestBody> map = new HashMap<>();
       map.put("description", description);
       map.put("place", place);
       map.put("time", time);

      // finally, execute the request
      Call<ResponseBody> call = service.uploadFileWithPartMap(map, body);
      call.enqueue(...);
      */
    @Multipart
    @POST
    @CheckResult
    Call<ResponseBody> uploadFileWithPartMap(
            @Url() String url,
            @PartMap() Map<String, String> parammap,
            @Part MultipartBody.Part file);

}
